import { selectorMixin } from "../selector";
import { getMajorByNameService } from "../../api/school";

Component({
  behaviors: [selectorMixin],
  data: {
    list: [],
    searchText: "",
  },
  methods: {
    onSearchInput: async function (e) {
      const searchText = e.detail.value;
      const majorList = (await getMajorByNameService(searchText)).data;
      this.setData({
        searchText,
        list: majorList,
      });
    },
    onSelectItem(e) {
      const item = e.currentTarget.dataset.item;
      this.emitSelect(item);
      this.closeSelector();
    },
  },
});
